<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章中心--->修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
</head>
    <body>
    <input type="hidden" id="Type" value="${drug.pid}"/>
        <form class="layui-form" id="formUpdate">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" id="id" name="id" value="${drug.id}" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>药品分类</label>
                <div class="layui-input-inline typeSelect">
                    <select name="pid" id="dtype">
                        <option value="0">-请选择-</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>药品名字</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name"  value="${drug.name}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>药品功效</label>
                <div class="layui-input-inline">
                    <input type="text" id="effect" name="effect"  value="${drug.effect}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上架时间</label>
                <div class="layui-input-inline">
                    <input type="text" id="test1"
                           name="buytime"  value="${drug.buytime}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">修改时间</label>
                <div class="layui-input-inline">
                    <input type="text" id="test2"
                           name="updatetime"  value="${drug.updatetime}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>价格</label>
                <div class="layui-input-inline">
                    <input type="text" id="price" name="price" value="${drug.price}" class="layui-input">
                </div>
            </div>
            <button class="layui-btn" type="button"  lay-filter="update" lay-submit="">保存修改</button>
        </form>
    </body>

    <script type="text/javascript">

        layui.use(['form','jquery','laydate'], function(){
            var form = layui.form;
            var $ = layui.jquery;
            var laydate = layui.laydate;
            laydate.render({
                elem : '#test1' //指定元素
            });laydate.render({
                elem : '#test2' //指定元素
            });
            $(function () {
                var pid = $("#Type").val();
                $.ajax({
                    type: 'post',
                    url: '/manage/drug/Pharmacy',
                    success: function (res) {
                        if (res.length > 0) {
                            for (var i = 0; i <= res.length; i++) {
                                if (pid == String(res[i].pid)) {
                                    $("#dtype").append("<option value='" + res[i].pid + "' selected='selected'>" + res[i].pname + "</option>")
                                } else {
                                    $("#dtype").append("<option value='" + res[i].pid + "'>" + res[i].pname + "</option>")
                                }
                                form.render();
                            }
                        }
                    }
                })
            })
            // 监听提交
           form.on('submit(update)', function(){
                $.ajax({
                    url:'/manage/drug/update',
                    type:'post',
                    data:$("#formUpdate").serialize(),
                    success:function(result){
                        alert(result);
                        window.parent.location.reload();
                    },
                    error:function(result){
                        //alert("失败？请及时告知开发人员"+result);
                        window.parent.location.reload();
                    }
                });
            });

        });

    </script>
</html>